﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using CrystalDecisions.CrystalReports.Engine;
using System.Data;

namespace VfAccountApps.WebForm
{
    public partial class ReportForm : System.Web.UI.Page
    {
        private ReportDocument TotalRptDoc = new ReportDocument();

        private ReportDataSet reportDataSet = new ReportDataSet(); // .xsd file name
        private DataTable reportDt = new DataTable();
        private string _query = string.Empty;

        protected void Page_Load(object sender, EventArgs e)
        {
            // Just set the name of data table
            reportDt.TableName = "ReportTable";

            _query = "select * from sap_info s, budget_info b "
                        + " where "
                        + " s.sap_info_id = b.sap_info_id";


            reportDt = DatabaseHelper.select(_query); //This function is located below this function
            reportDataSet.Tables["ReportTable"].Merge(reportDt);
            
            // Your .rpt file path will be below
            TotalRptDoc.Load(Server.MapPath("../WebForm/MonthlyReport.rpt"));

            //set dataset to the report viewer.
            TotalRptDoc.SetDataSource(reportDataSet);
            CrystalReportViewer1.ReportSource = TotalRptDoc;
        }

        protected void Page_Unload(object sender, EventArgs e)
        {
            TotalRptDoc.Close();
            TotalRptDoc.Dispose();
        }
    }
}